﻿Imports System.Threading
Imports System.Windows.Threading

Class Application

    ' Ereignisse auf Anwendungsebene wie Startup, Exit und DispatcherUnhandledException
    ' können in dieser Datei verarbeitet werden.

    Private Sub Application_Startup(ByVal sender As Object, ByVal e As System.Windows.StartupEventArgs) Handles Me.Startup
        AddHandler DispatcherUnhandledException, AddressOf CurrentDomain_DispatcherUnhandledException
#If Not Debug Then

        AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException
#End If

        If e.Args.Count > 0 Then
            Try
                arguments = e.Args(0)
            Catch ex As Exception
                arguments = ""
            End Try
        End If
    End Sub

    Public dLoadSplash As New _dLoadSplash(AddressOf LoadSplash)
    Public Delegate Sub _dLoadSplash(ByVal w As SplashScreen)
    Private arguments As String

    Private Sub LoadSplash(ByVal w As SplashScreen)
        Dispatcher.BeginInvoke(New Action(AddressOf CreateMainWindow), DispatcherPriority.Send, Nothing)
    End Sub

    Private Sub CreateMainWindow()
        MainWindow = New Window1
        MainWindow.Show()
    End Sub

#Region "CrashHandler"
    ''' <summary>
    ''' Methode zum Abfangen von unbehandelten Ausnahmen. Die Fehlermeldung wird an eine neue Instanz von CrashReporter weitergegeben.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Shared Sub CurrentDomain_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
        Dim ErrorDlg As CrashReporter = New CrashReporter(CType(e.ExceptionObject, Exception))
        ErrorDlg.ShowDialog()
    End Sub

    Public Shared Sub CurrentDomain_DispatcherUnhandledException(ByVal sender As Object, ByVal e As DispatcherUnhandledExceptionEventArgs)
        Dim ErrorDlg As CrashReporter = New CrashReporter(CType(e.Exception, Exception))
        ErrorDlg.ShowDialog()
    End Sub
#End Region
End Class
